package com.cloud.pole.shop.biz.goods;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.goods.ShopGoodsCategoryMapper;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsCategory;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ShopGoodsCategoryBiz extends BaseBiz<ShopGoodsCategoryMapper, ShopGoodsCategory> {

	@Cache(key="shopGoodsCategory:cateLevel{1}")
    public List<ShopGoodsCategory> selectListByCateLevel(Integer cateLevel) {
		 Example example = new Example(ShopGoodsCategory.class);
		 Criteria criteria = example.createCriteria();
         criteria.andEqualTo("cateLevel", cateLevel);
         criteria.andEqualTo("showStatus", ShopGoodsCategory.SHOW_STATUS_YES);
         example.setOrderByClause("order_level");
		 return selectByExample(example);
    }

	@Cache(key="shopGoodsCategoryList")
    public List<ShopGoodsCategory> selectAllList() {
		 Example example = new Example(ShopGoodsCategory.class);
		 Criteria criteria = example.createCriteria();
		 criteria.andEqualTo("showStatus", ShopGoodsCategory.SHOW_STATUS_YES);
         example.setOrderByClause("order_level");
		 return selectByExample(example);
    }
	
	@Cache(key="shopGoodsCategoryList{1}-shopId-categoryList")
    public List<ShopGoodsCategory> selectListByShopId(Integer shopId) {
		 Example example = new Example(ShopGoodsCategory.class);
		 Criteria criteria = example.createCriteria();
		 criteria.andEqualTo("showStatus", ShopGoodsCategory.SHOW_STATUS_YES);
		 criteria.andEqualTo("shopId", shopId);
         example.setOrderByClause("order_level");
		 return selectByExample(example);
    }


	@CacheClear(keys= {"shopGoodsCategory:cateLevel{1.cateLevel}", 
			"shopGoodsCategoryList",
			"shopGoodsCategoryList{1.shopId}-shopId-categoryList"})
    public void insertUseGeneratedKeys(ShopGoodsCategory record) {
        mapper.insertUseGeneratedKeys(record);
    }
    
    @Override
    @CacheClear(keys= {"shopGoodsCategory:cateLevel{1.cateLevel}", 
			"shopGoodsCategoryList",
			"shopGoodsCategoryList{1.shopId}-shopId-categoryList"})
    public void updateSelectiveById(ShopGoodsCategory record) {
    	super.updateSelectiveById(record);
    }
    
    public List<ShopGoodsCategory> selectByOne(){
    	return mapper.selectByPot();
    }
    
    public List<ShopGoodsCategory> selectByCodeGoods(String supId){
    	return mapper.selectByGoodsCode(supId);
    }

}
